export const useStateRouter = () => {
  const route = useRoute();
  const router = useRouter();

  /** 保留原有route值, 追加路由params及query参数 */
  const statePush = (newQuery: any, newParams?: any) => {
    const params = Object.assign({}, route.params || {}, newParams || {});
    const query = Object.assign({}, route.query || {}, newQuery || {});

    router.push({ name: route.name!, params, query });
  };

  /** 保留原有route值, 删除指定params及query参数 */
  const stateBack = (delQueryKeys: string[], delParamsKeys?: string[]) => {
    const params = Object.assign({}, route.params || {});
    const query = Object.assign({}, route.query || {});

    delParamsKeys?.map((key) => delete params[key]);
    delQueryKeys?.map((key) => delete query[key]);

    router.push({ name: route.name!, params, query });
  };

  return {
    /** 保留原有route值, 追加路由params及query参数 */
    statePush,
    /** 保留原有route值, 删除指定params及query参数 */
    stateBack,
    /** 当前route */
    route
  };
};
